﻿#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
	srand((unsigned int)time(NULL));
	int r = rand() % 100 + 1;
	int guss;
	int count = 5;
	printf("欢迎来到猜数字游戏！\n请输入一个在1~100之间的数：\n");
	scanf("%d", &guss);
	if (guss > r)
		printf("猜大了\n");
	if (guss < r)
		printf("猜小了\n");
	if (guss == r)
	{
		printf("恭喜你，猜对了！\n");
	}
	count--;
	while (count != 0 && guss!=r)
	{
		printf("你还有%d次机会。", count);
		printf("请重新输入：\n");
		scanf("%d", &guss);
		if (guss > r)
			printf("猜大了\n");
		if (guss < r)
			printf("猜小了\n");
		if (guss == r)
		{
			printf("恭喜你，猜对了！\n");
			break;
		}
		count--;
	} 
	if (count == 0)
		printf("你失败了，正确值是:%d\n", r);
	return 0;
}